﻿using System;
using System.IO;
using System.Web.UI;
using Business;

public partial class Pages_Upload : Page
{
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
        {
            var path = Config.ImagePath + DateTime.Now.ToString("yyyyMM");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            var fn = Path.GetFileName(FileUpload1.PostedFile.FileName);
            var saveLocation = path + "\\" + fn;
            try
            {
                FileUpload1.PostedFile.SaveAs(saveLocation);
                hdfkey.Value = Config.ImageUrl + DateTime.Now.ToString("yyyyMM") + "/" + fn;

            }
            catch (Exception ex)
            {
                Config.Message(Page, Resources.Resource.Systemerror);
                //Note: Exception.Message returns a detailed message that describes the current exception. 
                //For security reasons, we do not recommend that you return Exception.Message to end users in 
                //production environments. It would be better to put a generic error message. 
            }
        }
        else
        {
            Config.Message(Page, Resources.Resource.SelectFile);
        }
    }
}
